// Tetris piece class.
// A Tetris piece is represented as a SIZE x SIZE boolean array, where the true cells
// give the location of the piece within this SIZE x SIZE box.
// This type is immutable.
public class TetrisPiece {
// The number of different kinds of pieces.
private static final int NKINDS = 7;
// The piece lives in a SIZE x SIZE box of cells.
private static final int SIZE = 4;
// How many kinds of pieces are there?
public static int getNumKinds() {
return NKINDS;
}
// How large are the pieces?
public static int getSize() {
return SIZE;
}
// Constructor: Return a piece of specified kind.
public TetrisPiece(int kind) {
}
// Factory method: Return a random piece.
public static TetrisPiece makeRandom() {
int kind = (int) Math.floor( (double) NKINDS * Math.random() );
return new TetrisPiece(kind);
}
// What kind is this piece?
public int getKind() {
return 0;
}
// Does this piece occupy the given cell in its SIZE x SIZE box?
public boolean get(int row, int col) {
return true;
}
// Return a new piece that represents this piece rotated in the given direction.
// If dir==0, then do no rotation.
// If dir>0, then rotate clockwise 90 degrees.
// If dir<0, then rotate counterclockwise 90 degrees.
public TetrisPiece rotate(int dir) {
return this;
}
}